package com.wsy.servlet;

import com.wsy.pojo.Department;
import com.wsy.service.DepartmentService;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "DepartmentServlet",urlPatterns = "/add.html")
public class DepartmentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        ServletContext app=this.getServletContext();
        ApplicationContext ac= WebApplicationContextUtils.getWebApplicationContext(app);
        DepartmentService departmentService= (DepartmentService) ac.getBean("departmentService");
        List<Department> list=departmentService.getAll();

        request.setAttribute("list",list);

        request.getRequestDispatcher("addattendence.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
